﻿using System;

namespace NotAClue.ComponentModel.DataAnnotations
{
    /// <summary>
    /// Attribute to identify which column to use as a 
    /// parent column for the child column to depend upon
    /// </summary>
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
    public class MenuAttribute : Attribute, IComparable
    {
        // this property is required to work with "AllowMultiple = true" ref David Ebbo
        // As implemented, this identifier is merely the Type of the attribute. However, 
        // it is intended that the unique identifier be used to identify two 
        // attributes of the same type.
        public override object TypeId { get { return this; } }

        public static MenuAttribute Default = new MenuAttribute();

        /// <summary>
        /// Gets or sets the name of the menu.
        /// </summary>
        /// <value>The name of the menu.</value>
        public String Name { get; private set; }

        /// <summary>
        /// Gets or sets the parent.
        /// </summary>
        /// <value>The parent.</value>
        public String Parent { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether this <see cref="MenuAttribute"/> is show.
        /// </summary>
        /// <value><c>true</c> if show; otherwise, <c>false</c>.</value>
        public Boolean Show { get; set; }

        /// <summary>
        /// Gets or sets the order.
        /// </summary>
        /// <value>The order.</value>
        public int Order { get; set; }

        /// <summary>
        /// Gets or sets the image path.
        /// </summary>
        /// <value>The image path.</value>
        public String ImagePath { get; set; }

        /// <summary>
        /// Gets or sets the description.
        /// </summary>
        /// <value>The description.</value>
        public String Description { get; set; }

        public Boolean RootMenu { get; set; }

        /// <summary>
        /// Gets or sets the action for this menu item.
        /// </summary>
        /// <value>The action.</value>
        /// <remarks></remarks>
        public PageTemplate Action { get; set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="MenuAttribute"/> class.
        /// </summary>
        public MenuAttribute()
        {
            Name = String.Empty;
            Parent = String.Empty;
            ImagePath = String.Empty;
            Show = false;
            RootMenu = false;
            Order = 0;
            Action = PageTemplate.None;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="MenuAttribute" /> class.
        /// </summary>
        /// <param name="menuName">Name of the menu.</param>
        public MenuAttribute(String menuName)
        {
            Name = menuName;
            Show = true;
            if (String.IsNullOrEmpty(Parent) && RootMenu)
                Parent = Name;
        }

        ///// <summary>
        ///// Initializes a new instance of the <see cref="MenuAttribute"/> class.
        ///// </summary>
        ///// <param name="menuName">Name of the menu.</param>
        //public MenuAttribute(String menuName, Boolean rootMenu)
        //{
        //    Name = menuName;
        //    RootMenu = rootMenu;
        //    Show = true;
        //}

        ///// <summary>
        ///// Initializes a new instance of the <see cref="MenuAttribute"/> class.
        ///// </summary>
        ///// <param name="show">if set to <c>true</c> [show].</param>
        //public MenuAttribute(Boolean show)
        //{
        //    Show = show;
        //}

        #region IComparable Members
        public int CompareTo(object obj)
        {
            return Order - ((MenuAttribute)obj).Order;
        }
        #endregion
    }
}